//
//  LSPatternButton.m
//  CROSBY
//
//  Created by Harvey on 2018/3/28.
//  Copyright © 2018年 Haley. All rights reserved.
//

#import "LSPatternButton.h"

@interface LSPatternButton()

@property (strong, nonatomic) UIImageView            *patternImageView;

@end

@implementation LSPatternButton

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews
{
    _patternImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:_patternImageView];
}

- (void)setPatternImage:(UIImage *)patternImage
{
    if (_patternImage == patternImage) {
        return;
    }
    
    _patternImage = patternImage;
    CGSize imageSize = _patternImage.size;
    CGFloat patternH = (kWidth-6) * imageSize.height / imageSize.width;
    _patternImageView.image = patternImage;
    _patternImageView.frame = CGRectMake(3, 5, kWidth-6, patternH);
    
    self.bounds = CGRectMake(0, 0, kWidth, patternH + 10);
}

@end
